//
//  AppendMultipleFishpondViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/25.
//

#import "AppendMultipleFishpondViewController.h"
#import "AppendFishpondHeaderView.h"
#import "AppendFishpondFooterView.h"
#import "AppendFishpondTableViewCell.h"
#import "AddPondModel.h"
#import "YTSelectStringShowView.h"
#import "getPondTissueListModel.h"
#import "DTChoosePersonListShowView.h"
#import "AppendMultipleFishpondHeaderView.h"
#import "AppendMultipleFishpondFooterView.h"
#import "SetupWorkViewController.h"
#import "YTTipsShowView.h"
#import "PersonInCchargeShowView.h"
#import "foundQuestSelectPondShowView.h"

@interface AppendMultipleFishpondViewController ()
@property (nonatomic ,strong) UIButton * tjBtn;
@property (nonatomic ,strong) AddPondModel * model;
@property (nonatomic ,strong) NSArray <pondTypeModel *>* TypemodelArray;
///是否是最后一步
@property (nonatomic ,assign) BOOL isLast;
@property (nonatomic ,strong) UIView * addTKview;
@end

@implementation AppendMultipleFishpondViewController
- (void)setIsLast:(BOOL)isLast{
    _isLast = isLast;
    [self.addTKview mas_updateConstraints:^(MASConstraintMaker *make) {
        if (isLast) {
            make.height.offset(0);
        } else {
            make.height.offset(kwt(47));
        }
    }];
}

- (NSArray<pondTypeModel *> *)TypemodelArray{
    if(!_TypemodelArray){
        _TypemodelArray = [NSArray array];
    }
    return _TypemodelArray;
}

- (AddPondModel *)model{
    if(!_model){
        NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject];
        NSString *accountPath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"AppendMultipleFishpondViewController%@",[UserInfoModel shared].OrgCode]];
        _model = [NSKeyedUnarchiver unarchiveObjectWithFile:accountPath];
        if(!_model){
            _model = [AddPondModel new];
        }
        _model.batchFlag = 1;
        if(_model.addPondModelList.count < 1){
            [_model.addPondModelList addObject:[addPondModelListModel new]];
            [_model.addPondModelList addObject:[addPondModelListModel new]];
        }
    }
    return _model;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.shutDownBack = YES;
    self.NoDataHidden = YES;
    [self setupView];
    [self loadNewData];
    // Do any additional setup after loading the view.
}
///池塘类型.默认选第一个
- (void)loadNewData {
    [self.view showBusyHUD];
    [SCNetManger PostPondTypeGetOptionWithDict: [NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <pondTypeModel *>* array = [NSArray yy_modelArrayWithClass:pondTypeModel.class json:model.result ];
            self.TypemodelArray = array;
//            self.model.typeId = array.firstObject.ID;
//            self.model.typeName = array.firstObject.name;
//            self.model.addPondModelList.firstObject.typeName = array.firstObject.typeName;
            [self.tableview reloadData];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}

- (void)back{
    if(self.isLast){
        self.isLast = NO;
        [self.tableview reloadData];
    } else {
        [super back];
    }
}

- (void)setupView{
    UIView * topview = [UIView new];
    topview.backgroundColor = KcolorHex(@"#0967FF");
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX);
    }];
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf back];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44);
        make.left.bottom.offset(0);
        make.width.offset(kwt(140));
    }];
    
    UIImageView * leftimg = kimageView(@"white_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UILabel * leftlab = [DTKTool labelWithText:@"批量新增池塘" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [backview addSubview:leftlab];
    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(43));
        make.centerY.offset(0);
    }];
    
    
    UIView * buttomview = [UIView new];
    buttomview.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:buttomview];
    [buttomview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(63)+ KSafeAreaBottomHeight);
    }];
    
    UIView * BCview = [UIView new];
    BCview.addClickBlock(^{
        [weakSelf BCBtnClick];
    });
    [buttomview addSubview:BCview];
    [BCview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(0);
        make.height.offset(kwt(63));
        make.width.offset(kwt(105));
    }];
    
    UIImageView * gzimg = kimageView(@"moban_save");
    [BCview addSubview:gzimg];
    [gzimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(10));
        make.width.height.offset(kwt(20));
    }];
    
    UILabel * gzlab = [DTKTool labelWithText:@"保存" andFont:kCFont(16) andTextColor:KcolorHex(@"#222222")];
    [BCview addSubview:gzlab];
    [gzlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(kwt(37));
    }];
    
    UIButton * tjBtn = [UIButton buttonWithType:0];
    self.tjBtn = tjBtn;
    tjBtn.addNormalText(@"下一步").addNormalColor(UIColor.whiteColor).addFont(kCFont(18)).addbackgroundColor([UIColor gradientColorWithSize:CGSizeMake(kwt(260), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#427FFF") endColor:KcolorHex(@"#3D5FFF")]).addTarget(self,@selector(TJBtnClick));
    [DTKTool YJ:kwt(10) andView:tjBtn];
    [buttomview addSubview:tjBtn];
    [tjBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(kwt(260));
        make.height.offset(kwt(48));
        make.right.offset(kwt(-10));
        make.top.offset(kwt(7.5));
    }];
    
    UIView * addTKview = [UIView new];
    addTKview.clipsToBounds = YES;
    self.addTKview = addTKview;
    addTKview.addClickBlock(^{
        if(weakSelf.model.addPondModelList.count < 99){
            [weakSelf.model.addPondModelList addObject:[addPondModelListModel new]];
            [weakSelf.tableview reloadData];
        } else {
            [weakSelf.view showWarning:@"不能更多了"];
        }
    });
    [DTKTool BFYJ:kwt(10) andView:addTKview andCorner:UIRectCornerTopLeft|UIRectCornerTopRight andSize:CGRectMake(0, 0, SCREEN_WIDTH, kwt(47))];
    addTKview.backgroundColor = KcolorHex(@"#F6F7F9");
    [self.view addSubview:addTKview];
    [addTKview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(kwt(47));
        make.bottom.equalTo(buttomview.mas_top);
    }];
    
    UILabel * addlab = [DTKTool labelWithText:@"+新增池塘" andFont:kCFont(17) andTextColor:KcolorHex(@"#0967FF")];
    [addTKview addSubview:addlab];
    [addlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
    [self.view addSubview:self.tableview];
    self.tableview.backgroundColor = KcolorHex(@"#ECEDEE");
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
        make.bottom.equalTo(addTKview.mas_top);
    }];
    
}


-(void)BCBtnClick{
    ///保存
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject];
    NSString *accountPath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"AppendMultipleFishpondViewController%@",[UserInfoModel shared].OrgCode]];
    [NSKeyedArchiver archiveRootObject:self.model toFile:accountPath];
    [self.view showWarning:@"保存成功"];
}

- (void)TJBtnClick{
    if(self.isLast){
        [self setupWork];
    } else {
        
        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:@{@"orgCode":[UserInfoModel shared].OrgCode}];
        NSMutableArray * nameAndTissueIdList = [NSMutableArray array];
        for (addPondModelListModel * model in self.model.addPondModelList) {
            if(model.name.length < 1){
                [self.view showWarning:@"请输入池塘名称"];
                return;
            }
            if(model.tissueId.length < 1){
                [self.view showWarning:@"请输入池塘编组"];
                return;
            }
            NSMutableDictionary * AndTissueIdList = [NSMutableDictionary dictionary];
            [AndTissueIdList setObject:model.name forKey:@"name"];
            [AndTissueIdList setObject:model.tissueId forKey:@"tissueId"];
            [nameAndTissueIdList addObject:AndTissueIdList];
        }
        [dict setObject:nameAndTissueIdList forKey:@"nameAndTissueIdList"];
        [self.view showBusyHUD];
        [SCNetManger PostPondManageIsDuplicateNameWithDict:dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
            [self.view hideBusyHUD];
            if(model.code == 200){
                NSNumber *boolNumber = [model.result objectForKey:@"isOk"]; // 或者使用 valueForKey:@"isOn"
                if([boolNumber boolValue]){
                    ///要做数据判断
                    self.isLast = YES;
                    [self.tableview reloadData];
                    
                } else {
                    [self.view showWarning:@"池塘名称重复,请重新取名"];
                }
            } else {
                [self.view showWarning:model.message];
            }
        }];
        
    }
}
///获取模版
- (void)setupWork{
    if(self.model.breedTypeId.length < 1){
        [self.view showWarning:@"请选择养殖种类"];
        return;
    }
    if(self.model.breedCycle.intValue < 1){
        [self.view showWarning:@"请输入养殖周期"];
        return;
    }
    
    
    if(self.model.directorName.length < 1){
        [self.view showWarning:@"请选择负责人"];
        return;
    }
    if(self.model.area.floatValue == 0){
        [self.view showWarning:@"请输入池塘面积"];
        return;
    }
    if(self.model.pictureImgArray.count < 1){
        [self.view showWarning:@"请上传池塘照片"];
        return;
    }
    if(self.model.templateId.length < 1){
        [self.view showWarning:@"请选择工作模版"];
        return;
    }
    if(self.model.executeDate.length < 1){
        [self.view showWarning:@"请选择工作执行时间"];
        return;
    }
    [self.view showBusyHUD];
    NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:@{@"id":self.model.templateId}];
    if(self.model.templateType.intValue == 1){    ///公共模版
        ///公共模版
        [SCNetManger PostMBDetailWithDict:dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
            [self.view hideBusyHUD];
            if(model.code == 200){
                TemplateFoundDetailsModel * m = [TemplateFoundDetailsModel yy_modelWithJSON:model.result];
                [m seledModel];
                for (TemplateFoundDetailsStepModelListModel * stempmodel in m.stepModelList) {///要按照新建的模版来处理
                    stempmodel.templateStepId = @"";
                }
                for (TemplateFoundDetailsStepModelListModel * listmodel in m.stepModelList) {
                    for (TemplateFoundDetailsTaskTypeModelListModel * taskModel in listmodel.taskTypeModelList) {
                        taskModel.sourceFlag = 1;
                    }
                }
                SetupWorkViewController * vc = [SetupWorkViewController new];
                self.model.stepModelList = [NSMutableArray arrayWithArray: m.stepModelList];
                self.model.templateVersionNumber = m.version;
                vc.model = self.model;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                [self.view showWarning:model.message];
            }
        }];
        
    }else  if(self.model.templateType.intValue == 2) {
        [SCNetManger PostGRMBDetailWithDict:dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
            [self.view hideBusyHUD];
            if(model.code == 200){
                TemplateFoundDetailsModel * m = [TemplateFoundDetailsModel yy_modelWithJSON:model.result];
                [m seledModel];
                for (TemplateFoundDetailsStepModelListModel * stempmodel in m.stepModelList) {///要按照新建的模版来处理
                    stempmodel.templateStepId = @"";
                }
                SetupWorkViewController * vc = [SetupWorkViewController new];
                self.model.stepModelList = [NSMutableArray arrayWithArray: m.stepModelList];
                self.model.templateVersionNumber = m.version;
                vc.model = self.model;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                [self.view showWarning:model.message];
            }
        }];
    } else {
        [self.view hideBusyHUD];

    }
    
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    AppendMultipleFishpondHeaderView * headerview = [AppendMultipleFishpondHeaderView NewView];
    headerview.model = self.model;
    MJWeakSelf
    headerview.openTKLXBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openTKLX:model];
    };
    headerview.openReloadBlock = ^{
        [weakSelf.tableview reloadData];
    };
    return headerview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if(self.isLast){
        return 0;
    }
    return kwt(210);
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(self.isLast == NO){
        AppendMultipleFishpondFooterView * view = [AppendMultipleFishpondFooterView new];
        return view;
    }
    
    AppendFishpondFooterView * footerview = [AppendFishpondFooterView NewView];
    footerview.model = self.model;
    MJWeakSelf
    //选择负责人
    footerview.openFZRBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openFZR:model];
    };
    ///选择工作模版
    footerview.openGZMBBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openGZMB:model];
    };
    ///选择批量打卡
    footerview.openPLDKBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openPLDK:model];
    };
    ///选择工作时间
    footerview.openGZSJBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openGZSJ:model];
    };
    
    ///打开照片
    footerview.openImageBlock = ^(AddPondModel * _Nonnull model, int index) {
        [weakSelf openImgArray:model.pictureImgArray andindex:index];
    };
    ///删除照片
    footerview.deleteImageBlock = ^(AddPondModel * _Nonnull model, int index) {
        
        [weakSelf.model.pictureImgArray removeObjectAtIndex:index];
        if(weakSelf.model.TJpictureImgArray.count > index){
            [weakSelf.model.TJpictureImgArray removeObjectAtIndex:index];
        }
        [weakSelf.tableview reloadData];
    };
    ///添加照片
    footerview.openAddImageBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openXJWithType:ACMediaPickerSourceFromAll andBlock:^(NSArray<ACMediaModel *> * _Nonnull list) {
            [SCNetManger PostuploadFilesWithImg:list.firstObject.image CompletionHandler:^(NSString * _Nonnull url, NSString * _Nonnull previewUrl, UIImage * _Nonnull img) {
                
                [weakSelf.model.pictureImgArray addObject:previewUrl];
                [weakSelf.model.TJpictureImgArray addObject:url];
                [weakSelf.tableview reloadData];
            }];
        }];
    };
    ///养殖种类
    footerview.openYZZLBlock = ^(AddPondModel * _Nonnull model) {
        [weakSelf openYZZL:model];
    };
    return footerview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if(self.isLast){
        return kwt(487 + 120);
    }
    return kwt(20);
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(self.isLast){
        return 0;
    }
    return self.model.addPondModelList.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return kwt(45);
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MJWeakSelf
    AppendFishpondTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AppendFishpondTableViewCell"];
    if (cell == nil) {
        cell = [[AppendFishpondTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AppendFishpondTableViewCell"];
    }
    cell.model =  self.model.addPondModelList[indexPath.row];
    cell.Index = indexPath.row + 1;
    cell.openTKMZBlock = ^(addPondModelListModel * _Nonnull model) {
        [weakSelf openTKBZ:model];
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
}

///点击池塘类型
- (void)openTKLX:(AddPondModel *)model{
    int i = 0;
    int index = 0;
    NSMutableArray * array = [NSMutableArray array];
    for (pondTypeModel * typeModel in self.TypemodelArray) {
        if(typeModel.typeCode.intValue == 1){///养殖类
            if([typeModel.ID isEqualToString:model.typeId]){
                index = i;
            }
            [array addObject:typeModel.name];
            i ++;
        }
    }
    MJWeakSelf
    [YTSelectStringShowView showViewWithTitle:@"选择池塘类型" andIndex:index andDateArray:array andBlock:^(NSString * _Nonnull str) {
        for (pondTypeModel * typeModel in weakSelf.TypemodelArray) {
            if([str isEqualToString:typeModel.name]){
                weakSelf.model.typeId = typeModel.ID;
                weakSelf.model.typeName = typeModel.name;
                weakSelf.model.addPondModelList.firstObject.typeName = typeModel.typeName;
                weakSelf.model.breedTypeId = @"";
                weakSelf.model.breedTypeName = @"";
                weakSelf.model.templateId = @"";
                weakSelf.model.templateType = @"";
                weakSelf.model.templateName = @"";
                [weakSelf.tableview reloadData];
                return;
            }
        }
    }];
}
///池塘编组
- (void)openTKBZ:(addPondModelListModel *)Model{
    [self.view showBusyHUD];
    [SCNetManger PostPondTissueGetPondTissueListWithDict: [NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <getPondTissueListModel *>* array = [NSArray yy_modelArrayWithClass:getPondTissueListModel.class json:model.result ];
            getPondTissueListModel * mm = [getPondTissueListModel new];
            mm.children = array;
            if(Model.tissueId.length > 0){
                [mm modelWithSeledID:Model.tissueId];
            }
            NSLog(@"%@",array);
            MJWeakSelf
            [DTChoosePersonListShowView showViewWithArray:array andBlock:^(getPondTissueListModel * _Nonnull pondModel) {
                Model.tissueId = pondModel.ID;
                Model.tissueName = pondModel.TJname;
                
                [weakSelf.tableview reloadData];
            }];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
///养殖种类
- (void)openYZZL:(AddPondModel *)Model{
    [self.view showBusyHUD];
    [SCNetManger PostBreedTypeGetOptionWithDict: [NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <getPondTissueListModel *>* modelarray = [NSArray yy_modelArrayWithClass:getPondTissueListModel.class json:model.result ];
            for (NSString * ID in [Model.breedTypeId componentsSeparatedByString:@","]) {
                for (getPondTissueListModel * typeModel in modelarray) {
                    if([typeModel.ID isEqualToString:ID]){
                        typeModel.seled = YES;
                    }
                }
            }
            MJWeakSelf
            
            [foundYZZLSelectPondShowView showviewWithArray:modelarray andBlock:^(NSArray<NSString *> * _Nonnull array) {
                NSMutableArray * nameArray = [NSMutableArray array];
                NSMutableArray * idArray = [NSMutableArray array];
                
                for (getPondTissueListModel * typeModel in modelarray) {
                    for (NSString * ID in array) {
                        if([ID isEqualToString:typeModel.ID]){
                            [nameArray addObject:typeModel.name];
                            [idArray addObject:typeModel.ID];
                        }
                    }
                }
                weakSelf.model.breedTypeId = [idArray componentsJoinedByString:@","];
                weakSelf.model.breedTypeName = [nameArray componentsJoinedByString:@","];
                [weakSelf.tableview reloadData];
            }];
//            int i = 0;
//            int index = 0;
//            NSMutableArray * array = [NSMutableArray array];
//            for (getPondTissueListModel * typeModel in modelarray) {
//                if([typeModel.ID isEqualToString:Model.breedTypeId]){
//                    index = i;
//                }
//                [array addObject:typeModel.name];
//                i ++;
//            }
//            MJWeakSelf
//            [YTSelectStringShowView showViewWithTitle:@"选择养殖种类" andIndex:index andDateArray:array andBlock:^(NSString * _Nonnull str) {
//                for (getPondTissueListModel * typeModel in modelarray) {
//                    if([str isEqualToString:typeModel.name]){
//                        weakSelf.model.breedTypeId = typeModel.ID;
//                        weakSelf.model.breedTypeName = typeModel.name;
//                        [weakSelf.tableview reloadData];
//                        return;
//                    }
//                }
//            }];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
//选择负责人
- (void)openFZR:(AddPondModel *)Model{
    [self.view showBusyHUD];
    [SCNetManger PostGetPositionAndUserByOrgCodeWithDict: [NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <PositionUserModel *>* modelarray = [NSArray yy_modelArrayWithClass:PositionUserModel.class json:model.result];
            MJWeakSelf
            for (PositionUserModel * typeModel in modelarray) {
                for (PondUserModel * usermodel in typeModel.userModelList) {
                    if([Model.directorName isEqualToString:usermodel.realName]){
                        usermodel.isSeled = YES;
                    }
                }
            }
            [SearchPersonInCchargeShowView showviewWithTitle:@"负责人" andArray:modelarray andBlock:^(NSString * _Nonnull ID) {
                for (PositionUserModel * typeModel in modelarray) {
                    for (PondUserModel * usermodel in typeModel.userModelList) {
                        if([ID isEqualToString:usermodel.userId]){
                            weakSelf.model.directorPhone = usermodel.phone;
                            weakSelf.model.directorName = usermodel.realName;
                            [weakSelf.tableview reloadData];
                        return;
                        }
                    }
                }
            }];
            //            NSMutableArray <PondUserModel *>* newModelArray = [NSMutableArray array];
            //            for (PositionUserModel * typeModel in modelarray) {
            //                for (PondUserModel * usermodel in typeModel.userModelList) {
            //                    BOOL isHave = NO;
            //                    for (PondUserModel * newModel in newModelArray) {
            //                        if([newModel.userId isEqualToString:usermodel.userId]){
            //                            isHave = YES;
            //                        }
            //                    }
            //                    if(isHave == NO){
            //                        [newModelArray addObject:usermodel];
            //                    }
            //                }
            //            }
            //
            //            int i = 0;
            //            int index = 0;
            //            NSMutableArray * array = [NSMutableArray array];
            //            for (PondUserModel * typeModel in newModelArray) {
            //                if([Model.directorName isEqualToString:typeModel.realName]){
            //                    index = i;
            //                }
            //                [array addObject:typeModel.realName];
            //                i ++;
            //            }
            //
            //            [YTSelectStringShowView showViewWithTitle:@"选择负责人" andIndex:index andDateArray:array andBlock:^(NSString * _Nonnull str) {
            //                for (PondUserModel * typeModel in newModelArray) {
            //                    if([str isEqualToString:typeModel.realName]){
            //                        weakSelf.model.directorPhone = typeModel.phone;
            //                        weakSelf.model.directorName = typeModel.realName;
            //                        [weakSelf.tableview reloadData];
            //                        return;
            //                    }
            //                }
            //            }];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
///工作模版
- (void)openGZMB:(AddPondModel *)Model{
    [self.view showBusyHUD];
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.model.typeId forKey:@"pondId"];
    [SCNetManger PostTemplateOptionListWithDict:dict  andCompetionHandlerBlock:^(HTTPArrBase * model) {
        [self.view hideBusyHUD];
        if(model.code ==200){
            NSArray <templateOptionListModel *>* modelarray = [NSArray yy_modelArrayWithClass:templateOptionListModel.class json:model.result ];
            MJWeakSelf
            int i = 0;
            int index = 0;
            NSMutableArray * array = [NSMutableArray array];
            for (templateOptionListModel * typeModel in modelarray) {
                if([typeModel.ID isEqualToString:Model.templateId]){
                    index = i;
                }
                [array addObject:typeModel.name];
                i ++;
            }
            
            [YTSelectStringShowView showViewWithTitle:@"选择工作模版" andIndex:index andDateArray:array andBlock:^(NSString * _Nonnull str) {
                for (templateOptionListModel * typeModel in modelarray) {
                    if([str isEqualToString:typeModel.name]){
                        //                        if(Model.templateId.length < 1){///新增
                        weakSelf.model.templateId = typeModel.ID;
                        weakSelf.model.templateType = typeModel.templateType;
                        weakSelf.model.templateName = typeModel.name;
                        [weakSelf.tableview reloadData];
                        //                        } else {
                        //                            [YTTipsShowView showviewWithTips:@"是否变更工作内容" andRightBlock:^{
                        //                                weakSelf.model.templateId = typeModel.ID;
                        //                                weakSelf.model.templateType = typeModel.templateType;
                        //                                weakSelf.model.templateName = typeModel.name;
                        //                                [weakSelf.tableview reloadData];
                        //                            }];
                        //                        }
                        return;
                    }
                }
            }];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}
///是否批量
- (void)openPLDK:(AddPondModel *)model{
    MJWeakSelf
    return;///默认是
    [YTSelectStringShowView showViewWithTitle:@"是否批量" andIndex:(model.batchFlag == 1)? 0 : 1 andDateArray:@[@"是",@"否"]  andBlock:^(NSString * _Nonnull str) {
        weakSelf.model.batchFlag = [str isEqualToString:@"是"]?1:0;
        [weakSelf.tableview reloadData];
    }];
}
///执行时间
- (void)openGZSJ:(AddPondModel *)model{
    MJWeakSelf
    [BRDatePickerView showDatePickerWithMode:BRDatePickerModeYMD title:@"工作执行日期" selectValue:model.executeDate minDate:[NSDate new] maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
        weakSelf.model.executeDate = selectValue;
        [weakSelf.tableview reloadData];
    } resultRangeBlock:nil];
}
@end
